package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName: SysRoleController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 角色管理控制层
 * @Author 孤妤
 * @Date: 2023/12/4 20:25
 */
@RestController
@RequestMapping("/admin/system/sysRole")
@Tag(name = "角色管理")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询角色列表")
    public Result<PageInfo<SysRole>> findByPage(@PathVariable Integer pageNum,
                                                @PathVariable Integer pageSize,
                                                SysRoleDto sysRoleDto){
        PageInfo<SysRole> listPageInfo = sysRoleService.findByPage(pageNum,pageSize,sysRoleDto);
        return Result.build(listPageInfo, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/findById/{id}")
    @Operation(summary = "根据id查询角色信息")
    public Result<SysRole> findById(@PathVariable Integer id){
        SysRole sysRole = sysRoleService.findById(id);
        return Result.build(sysRole,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    @Operation(summary = "添加角色信息")
    public Result addSysRole(@RequestBody SysRole sysRole){
        sysRoleService.addSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("添加成功");
    }
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除角色信息")
    public Result removeById(@PathVariable Integer id){
        sysRoleService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }
    @PutMapping("/updateSysRole")
    @Operation(summary = "修改角色信息")
    public Result changeSysRole(@RequestBody SysRole sysRole){
        sysRoleService.changeSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
}
